package cn.itcast.order;

import com.itcast.feign.clients.UserClient;
import com.itcast.feign.config.DefaultFeignConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

//因为UserClient不在cn.itcast.order包下，feign无法扫描到里面注解，所以通过clients配置，或者通过basePackage配置包名
@EnableFeignClients(clients = UserClient.class,defaultConfiguration = DefaultFeignConfig.class)//开启feign客户端
@MapperScan("cn.itcast.order.mapper")
@SpringBootApplication
public class OrderApplication {

    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class, args);
    }

    @Bean
    @LoadBalanced // 开启负载均衡
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    /**
     * 配置全局随机负载均衡策略，这样配置后，所有的远程服务调用都会使用这种负载均衡策略
     * @return
     */
//    @Bean
//    public IRule randomRule(){
//        return new RandomRule();
//    }

}